package com.uenpay.im.entities;

import java.util.Locale;

import android.text.TextUtils;

public class FileType {
	public static final int FILE_DOC = 0;
	public static final int FILE_TXT = 1;
	public static final int FILE_HTML = 2;
	public static final int FILE_MP3 = 3;
	public static final int FILE_ZIP = 4;
	public static final int FILE_PPT = 5;
	public static final int FILE_IMAGE = 6;
	public static final int FILE_PDF = 7;
	public static final int FILE_XLS = 8;
	public static final int FILE_UNKNOW = 9;
	public static final int FILE_NO_FILE = 10;
	public static final int FILE_VIDEO = 11;
	public static final int FILE_APK = 12;

	public static int getFileType(String file_name) {

		try {
			String[] str =  file_name.split("\\.");
			String  temp_end =  str[str.length-1];
			String end = temp_end.toLowerCase(Locale.getDefault());
			if (TextUtils.isEmpty(end)) {
				return FILE_NO_FILE;
			} else {
				if (end.equals("ppt") || end.equals("pptx")) {
					return FILE_PPT;
				} else if (end.equals("txt")) {
					return FILE_TXT;
				} else if (end.equals("doc") || end.equals("docx")) {
					return FILE_DOC;
				} else if (end.equals("html")) {
					return FILE_HTML;
				} else if ((end.equals("jpg") || end.equals("gif")
						|| end.equals("png") || end.equals("jpeg")
						|| end.equals("bmp") || end.equals("wbmp")
						|| end.equals("ico") || end.equals("jpe"))) {
					return FILE_IMAGE;
				} else if (end.equals("pdf")) {
					return FILE_PDF;
				} else if (end.equals("zip") || end.equals("rar")) {
					return FILE_ZIP;
				} else if (end.equals("xls") || end.equals("xlsx")) {
					return FILE_XLS;
				} else if (end.equals("mp3") || end.equals("amr") || end.equals("m4a")) {
					return FILE_MP3;
				} else if (end.equals("mp4") || end.equals("mov") || end.equals("mv")) {
					return FILE_VIDEO;
				} else if (end.equals("apk")) {
					return FILE_APK;
				} else {
					return FILE_UNKNOW;
				}
			}

		} catch (Exception e) {
			return FILE_UNKNOW;
		}
	}
	
	public static String getFileTypeName(String file_name){
		String[] str =  file_name.split("\\.");
		String  temp_end =  str[str.length-1];
		String end = temp_end.toLowerCase(Locale.getDefault());
		return end;
	}
}
